package cn.bocweb.spinning.model.Factory;

import com.google.gson.Gson;

import java.io.IOException;
import java.lang.reflect.Type;

import cn.bocweb.spinning.util.DeviceUtil;
import okhttp3.ResponseBody;
import retrofit.Converter;

/**
 * Created by chenchangxing on 16/2/17.
 */
final class MyGsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
    private final Gson gson;
    private final Type type;

    MyGsonResponseBodyConverter(Gson gson, Type type) {
        this.gson = gson;
        this.type = type;
    }

    @Override
        public T convert(ResponseBody value) throws IOException {

            String jsonStr = value.string();
            DeviceUtil.Log(jsonStr);
            return gson.fromJson(jsonStr, type);
//        Reader reader = value.charStream();
//        try {
//            DeviceUtil.Log("Gson = " + gson);
//            return gson.fromJson(reader, type);
//        } finally {
//            Utils.closeQuietly(reader);
//        }
    }
}
